//加载进度条
var mprogress = new Mprogress({
    parent: '#process'
})

getData()
function  getData (data){
    if (data) {
        mprogress.start();
        mprogress.inc(0.3)
        $('.name').html(data.id_name)
        $('.user-sex').html(data.gender)
        $('.user-department').html(data.dept)
        $('.left').html(`<img style="width:100%;height:100%" alt="" src=${data.image} >`)
        setTime()
        setTimeout(() => {
            mprogress.end()
        }, 1000);
    } else {
        console.log('暂无数据')
        $('.name').html()
        $('.user-sex').html()
        $('.user-department').html()
        $('.left').html('<img style="width:100%;height:100%" alt=""   src= "./images/1.png">')
         setTime()
    }

}

// //数字滚动
// (function($, window, document) {
//   "use strict";
//   var defaults = {
//       deVal: 0,       //传入值
//       className:'dataNums',   //样式名称
//       digit:''    //默认显示几位数字
//   };
//   function rollNum(obj, options){
//     this.obj = obj;
//     console.log(obj,options)
//     this.options = $.extend(defaults, options);
//     console.log(options)
//       this.init = function(){
//            this.initHtml(obj,defaults);
//       }
//   }
//   rollNum.prototype = {
//       initHtml: function(obj,options){
//           var strHtml = '<ul class="' + options.className + ' inrow">';
//           var valLen = options.digit ||  (options.deVal + '').length;
//           if(obj.find('.'+options.className).length <= 0){
//               for(var i = 0; i<  valLen; i++){
//                   strHtml += '<li class="dataOne "><div class="dataBoc"><div class="tt" t="38"><span class="num0">0</span> <span class="num1">1</span> <span class="num2">2</span> <span class="num3">3</span> <span class="num4">4</span><span class="num5">5</span> <span class="num6">6</span> <span class="num7">7</span> <span class="num8">8</span> <span class="num9">9</span><span class="num0">0</span> <span class="num1">1</span> <span class="num2">2</span> <span class="num3">3</span> <span class="num4">4</span><span class="num5">5</span> <span class="num6">6</span> <span class="num7">7</span> <span class="num8">8</span> <span class="num9">9</span></div></div></li>';
//               }
//               strHtml += '</ul>';
//             obj.html(strHtml);
//             console.log(obj)
//           }
//             this.scroNum(obj, options);
//       },
//       scroNum: function(obj, options){
//           var number = options.deVal;
//           console.log('number',number)
//           var $num_item = $(obj).find('.' + options.className).find('.tt');
//         console.log('$num_item', $num_item)
//         console.log($(obj).find('.dataBoc'))
//           var h = $(obj).find('.dataBoc').height(); 
//          console.log("h",h)
//         $num_item.css('transition', 'all 2s ease-in-out');
//         console.log(number)
//           var numberStr = number.toString();
//           console.log("numberStr",numberStr.length)
//         if (numberStr.length <= $num_item.length - 1) {
//             console.log(1111)
//               var tempStr = '';
//               for(var a = 0; a < $num_item.length - numberStr.length; a++){
//                   tempStr += '0';
//               }
//               numberStr = tempStr + numberStr;
//           }

//         var numberArr = numberStr.split('');
//         console.log(numberArr)
//           $num_item.each(function(i, item) 
//           {
//             console.log(i, item)
//             console.log(-parseInt(numberArr[i])*h - h*10)
//             setTimeout(function () {
//                 console.log($num_item.eq(i))
//                   $num_item.eq(i).css('top',-parseInt(numberArr[i])*h - h*10 + 'px');
//               },i*100)
//           });
//       }
//   }
//   $.fn.rollNum = function(options){
//       var $that = this;
//       var rollNumObj = new rollNum($that, options);
//       rollNumObj.init();
//   };
// })(jQuery, window, document);



getData1()
function getData1(data) {
  if (data != undefined) {
       n = data;
    if (data == '0') {
      $('.title').css('background', 'url(./images/bz0.png) no-repeat center')
      $('.action').html('准备就绪')
      setTimeout(function ()
      {
        
        getT(n,0) 
       },10000)
    } else if (data == '1') {
      $('.title').css('background', 'url(./images/bz1.png) no-repeat center')
      $('.action').html('吹气')
      setTimeout(function ()
      {
      
        getT(n,1) 
       },10000)
    } else if (data == '2') {
      $('.title').css('background', 'url(./images/bz2.png) no-repeat center')
      $('.action').html(`指纹认证`)
      setTimeout(function ()
      {
       
        getT(n,2) 
       },10000)
    } else if (data == '3') {
      $('.title').css('background', 'url(./images/bz3.png) no-repeat center')
      $('.action').html('吹气')
      setTimeout(function ()
      {
      
        getT(n,3) 
       },10000)
    } else if (data == '4') {
      $('.action').html('异常操作')
      $('.right').css({
        "-webkit-animation":"twinkling 1s 10 1s ease-in-out alternate",
       "animation":"twinkling 1s 10 1s ease-in-out alternate"
      })
 
     
      setTimeout(function ()
      {
        $('.right').css('animation','none');
        getT(n,4) 
       },10000)
    }
  } else {
    $('.action').html('')
   
  }
}
//
function getT(x,y) {
    console.log(x)
    if (x == y) {
      $('.title').css('background', 'url(./images/moren.png) no-repeat center')
      $('.action').html('')
      $('.name').html()
      $('.user-sex').html()
      $('.user-department').html()
      $('.left').html('<img style="width:100%;height:100%" alt=""   src= "./images/1.png">')

    }
}

setInterval(function(){setTime()},1000)
function setTime(){
    var date = new Date()
    // console.log(getWeek(date))
    var time1 = date.getTime()
    var M = getTimeC(time1)
    let L = M.split(' ')
    let N = L[0].split('-')
    $('.y').html(N[0])
    $('.m').html(N[1])
    $('.d').html(N[2])
  $('.XQ').html(getWeek(date))
  let U = L[1].split(':').join('').split('')
 
  $('.rtime').html(
    `<span class="h-t">${U[0]}</span> <span  class="h-t">${U[1]}</span> : <span class="h-t">${U[2]}</span> <span class="h-t">${U[3]}</span>`
  )
}
    /************   时间戳转化   ************* */
	function  getTimeC(timestamp) {
		var date = new Date(timestamp);
		//console.log(date);
		let Y = date.getFullYear() + "-";
		let M =
		  (date.getMonth() + 1 < 10
			? "0" + (date.getMonth() + 1)
			: date.getMonth() + 1) + "-";
		let D =
		  (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
		let h =
		  (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
		let m =
		  (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
		  ":";
		let s =
		  date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		return Y + M + D + h + m + s;
}
function getWeek(date) {
    var week;
    if(date.getDay() == 0) week = "星期日"
    if(date.getDay() == 1) week = "星期一"
    if(date.getDay() == 2) week = "星期二"
    if(date.getDay() == 3) week = "星期三"
    if(date.getDay() == 4) week = "星期四"
    if(date.getDay() == 5) week = "星期五"
    if(date.getDay() == 6) week = "星期六"
    return week;
}